package com.yiba.vpn.util;

import java.util.Random;

/**
 * @author : tang
 * @createtime ：2018年1月2日 下午3:10:52
 * 
 */
public class RandomUtil {

	public static Integer routerStartNum = 9;
	public static Integer routerCountNum = 3;

	/**
	 * 随机返回 1 2 3
	 * 
	 * @return
	 */
	public static Integer PercentageRandom() {

		double rate1 = 0.60;
		double rate2 = 0.30;
		double rate3 = 0.10;

		double randomNumber;
		randomNumber = Math.random();
		if (randomNumber >= 0 && randomNumber <= rate1) {
			return 1;
		} else if (randomNumber >= rate1 / 100 && randomNumber <= rate1 + rate2) {
			return 2;
		} else if (randomNumber >= rate1 + rate2 && randomNumber <= rate1 + rate2 + rate3) {
			return 3;
		}
		return -1;
	}

	/**
	 * 随机生成6位密码
	 * 
	 * @return
	 */
	public static String createVerifyCode() {
		String str = "0123456789";
		StringBuilder sb = new StringBuilder(6);
		for (int i = 0; i < 6; i++) {
			char ch = str.charAt(new Random().nextInt(str.length()));
			sb.append(ch);
		}
		return sb.toString();
	}

	/**
	 * 路由活动专用随机数生成
	 * 
	 * @return
	 */
	public static Integer randomRouterInt() {
		Random random = new Random();
		return random.nextInt(routerCountNum) + routerStartNum;
	}

}
